{include file="public/public"}
<div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
    <div class="layui-body layui-tab-content site-demo site-demo-body">
        <div class="layui-tab-item layui-show">
            <div class="layui-main">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                </fieldset>
                <span class="layui-breadcrumb">
                    <a href="__APP__/{$menuConfigArry['functionMod']}/{$menuConfigArry['menuLabel']}">{$menuConfigArry['pmenuName']}</a>
                    <a><cite>{$menuConfigArry['menuName']}</cite></a>
                </span>
                <hr>

                <div class="layui-tab " style="margin-top: 20px;" >
                    <?php
                    if($childMenuArry){
                    ?>
                    <ul class="layui-tab-title">
                        <?php
                        foreach($childMenuArry as $cm){
                            if($method==$cm['menuLabel']){
                    ?>
                        <li  class="layui-this" ><a href="__APP__/{$cm['functionMod']}/{$cm['pmenuLabel']}?m={$cm['menuLabel']}">{$cm['menuName']}</a></li>
                        <?php
                            }else{
                            ?>
                        <li ><a href="__APP__/{$cm['functionMod']}/{$cm['pmenuLabel']}?m={$cm['menuLabel']}">{$cm['menuName']}</a></li>
                        <?php
                            }
                        }
                    ?>
                    </ul>
                    <?php
                    }
                   ?>

                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show" id="filmManagement">
                            <div class="layui-form-item">
                                <!--
                                    描述：搜索
                                -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">按角色查找：</label>
                                    <div class="layui-input-inline">
                                        <input id='souname'  name="text2" type="text" autocomplete="off" class="layui-input">
                                    </div>
                                    <a href="#" onClick="subsou()" class="layui-btn ">查询</a>
                                </div>
                            </div>
                            <!--
                                描述：主内容表格
                            -->
                            <div id='property_box_table'>
                                <table class="layui-table"  lay-skin="line">
                                   <thead >
                                    <tr>
                                        <td width="106">选择</td>
                                        <td width="103">编号</td>
                                        <td width="125" >账号角色</td>
                                        <td width="137">操作</td>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
									     	if($permissionArr){
									      		foreach($permissionArr as $val){
									   	?>
                                    <tr>
                                        <?php
										      		if($val[id]!=0){
										      	?>
                                        <td><input  type="checkbox" name="listbox" id="listbox"  value="{$val[id]}"></td>
                                        <?php
									        		}else{
									        	?>
                                        <td>&nbsp;</td>
                                        <?php
										        	}
										        ?>
                                        <td>{$val[id]}</td>
                                        <td>{$val[rolename]}</td>
                                        <td>
                                            <?php
										     		if($val[id]!=0){
										     	?>
                                            <a href="#" class="layui-btn  layui-btn-sm" onclick="edit('{$val[rolename]}','{$val[id]}','{$val[permission]}')">修改</a>
                                            <?php
													}
												?>
                                        </td>
                                    </tr>
                                    <?php
												}
											}
										?>
                                    </tbody>
                                </table>
                                <div class="content_glcz">管理操作：全选
                                    <input name="checkbox" type="checkbox" onClick="checkallstu(this)"/>
                                    <input name="submit" type="button" value="删除"  onclick="delall()" class="layui-btn layui-btn-sm layui-btn-warm layui-btn-sm"/>
                                    <input name="submit3" type="button" value="添加"  onclick="document.getElementById('property_box_new').style.display='block'" class="layui-btn  layui-btn-sm"/>
                                </div>
                                <!--
                                    描述：分页
                                -->
                                <div class="layui-box layui-laypage layui-laypage-default">{$page}</div>
                            </div>
                            <!--
                                描述：新增
                            -->
                            <div id="property_box_new" style="DISPLAY:none" class="show">
                                <table class='layui-table' lay-skin='line'>

                                    <tbody>
                                    <tr class="ctt_gr">
                                        <td width="276" align="right">角&nbsp;色&nbsp;名：</td>
                                        <td width="316" align="left"><input class='layui-input' type="textField_hp1" size="15" type="text" id="rolename" />
                                            <input type="hidden" id="id" name="id"></td>
                                    </tr>
                                    <?php
                                          	if($navigationMenuArry){
                                          	 $tmp = addslashes(json_encode($navigationMenuArry));
									      		      foreach($navigationMenuArry as $val){
									      		       $pmenuLabel = $val['pmenuLabel'];
									      		       $child=$val['child'];
									      		         ?>
                                    <tr class="ctt_gr">
                                        <th width="400" align="center"><input type="checkbox" name="checkbox" value="checkbox" onClick="checkallstu(this,'{$pmenuLabel}')" >{$val['pmenuName']}：</th>
                                        <?php
                                                 if($child){
                                                    foreach($child as $v){
                                                       ?>
                                        <td width="400" align="center"><input type="checkbox" name="{$pmenuLabel}" id="{$pmenuLabel}"   value="{$v['id']}"  >{$v['menuName']}</td>
                                        <?php
                                                    }
                                                 }
                                                ?>
                                    </tr>
                                    <?php
									      		      }
									      		    }
                                            ?>

                                    <tr class="ctt_gr">
                                        <td align="center"><input name="submit2" type="button" value="确定" border="0"  onClick='addadmin("{$tmp}")' class="layui-btn"/>
                                            <input name="submit22" type="button" value="取消" border="0" method="post"  onclick="document.getElementById
										('property_box_new').style.display='none'" class="layui-btn layui-btn-primary"/>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script language='javascript'>
    function myrefresh(){
        window.location.reload();
    }
    function edit(rolename,id,permission){
        $("#rolename").val(rolename);
        $("#id").val(id);
        //alert(permission);
        strArr = permission.split(',');
        for ( var i = 0; i < strArr.length; i++ ) {
            var valname = strArr[i];
            $("input[value='"+valname+"']").attr("checked",true);
        }
        $('#property_box_new').show();
    }
    function addadmin(val){
        var arr="";
        var json=JSON.parse(val);

        for(var i in json){
            $("input[name="+i+"]:checked").each(function(){
                arr+=$(this).val()+",";
            })
        }

        var rolename = $("#rolename").val();
        if(rolename==''){
            layer_msg('请填写角色名');
            return false;
        }
        if(arr==''){
            layer_msg('请选择权限');
            return false;
        }
        var id = $("#id").val();
        $.post("__APP__/system/addpermission",{
            rolename : rolename,
            arr : arr,
            id : id
        }, function(data) {
            if(data.msg=="1"){
                layer_alert("操作成功",1);
            }else if(data.msg=="2"){
                layer_alert("用户已经存在");
                $('#username').val("");
            }else{
                layer_alert("操作失败");
                return false;
            }
        },"json");
    }

    function subsou(){
        var souname = $("#souname").val();
        window.location.href='__APP__/system/accountPermissions?m=propertyManagement&name='+souname;
    }
    function checkallstu(o,c) {
        //alert(o);
        if(o.checked){
            $("input[name="+c+"]").attr("checked",true);
        }else{
            $("input[name= "+c+"]").attr("checked",false);
        }
    }
    function delall(){
        var arr="";
        $("input[name=listbox]:checked").each(function(){
            arr+=$(this).val()+",";
        })
        if(arr==""){
            layer_msg('请选择要删除的记录');
            return false;
        }
        layer.confirm('你确定要删除吗？', {icon: 3, title:'提示'}, function(index){
            $.post("__APP__/system/delallpermission",{
                arr : arr
            }, function(data) {
                if(data.msg=="1"){
                    layer_alert("删除成功",1);
                }else{
                    layer_alert("删除失败");
                    return false;
                }
            },"json");
        });
    }
    $('#souname').keydown(function(event){
        if(event.keyCode==13){
            subsou();
        }
    });

</script>
